package com.canca.web.util;


public class StringUtil {
	private static StringUtil util = new StringUtil();
	private StringUtil(){}
	public static StringUtil getInstance(){
		return util;
	}
    
	/**
	 * 首字母大写
	 * @param oldString
	 * @return
	 */
	public String initialUpperCase(String oldString){
		if(oldString == null || oldString.equals(""))return oldString;
		String target = new StringBuffer().append(oldString.substring(0,1).toUpperCase()).append(oldString.substring(1)).toString();
		return target;
	}
	
	/**
	 * 首字母小写
	 * @param oldString
	 * @return
	 */
	public String initialLowerCase(String oldString){
		if(oldString == null || oldString.equals(""))return oldString;
		String target = new StringBuffer().append(oldString.substring(0,1).toLowerCase()).append(oldString.substring(1)).toString();
		return target;
	}
	/**
	 * 去右空格
	 * @param str
	 * @return
	 */  
	public static String rtrim(String str){
		   int end;
		   if (str == null || (end = str.length()) == 0) {return str;}
		   while ((end != 0) && Character.isWhitespace(str.charAt(--end)));
		   return str.substring(0, end + 1);
	}
    
    /**
     * 去左空格
     * @param str
     * @return
     */
	public static String ltrim(String str){
		   int begin = -1;
		   int end;
		   if (str == null || (end = str.length()) == 0) {return str;}
		   while ((++begin < end) && Character.isWhitespace(str.charAt(begin)));
		   return str.substring(begin,end);
	}
    
    public static void main(String [] args){
    	System.out.println(util.ltrim("  a"));
    	System.out.println(util.rtrim("as"));
    }
}